home *** CD-ROM | disk | FTP | other *** search
- /*
- * Discussions.c
- *
- * This program source code and it's compiled version IS NOT IN THE
- * PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / WG" file for details
- * regarding use of this program source code and it's compiled version.
- *
- * 2/2/92 - Modified for Beta test release, N Hawthorn
- *
- */
-
-
- #define INMAIN
- #include <SetUpA4.h>
- #include "MUBBS Module.h"
-
- typedef struct EnterStruct{
- char FromUser[36]; /* The person who sent the message */
- char ToUser[36]; /* The person the message is to */
- char title[71]; /* The title of the message */
- int status; /* 0 = unread 1 = Read 2 = deleted */
- char NetAddress[21]; /* Fidonet address of the ToUser(UNUSED) */
- char reserved1[21]; /* Reserved, do not use */
- char reserved2[21]; /* Reserved, do not use */
- long int offset; /* Offset of the message in Email.Text */
- long int length; /* Length of message in chars */
- int numlines; /* */
- char DateSent[26]; /* String of Date/Time sent */
- char emailtext[51][82]; /* The text of the email message */
- int result; /* Result to pass back */
-
- };
-
- int last_read[maxport]; /* this is a global */
-
-
- pascal void main (mode1,G1,P1) /* called from the main routines, and what mode to be in */
- int mode1;
- struct GS *G1; /* we point to the "global" struct in the Main Module here */
- Ptr P1; /* we ignore this pointer, we do not use it at all */
- {
- Handle temph;
- float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
- RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
- asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
-
- G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
- mode[u]=mode1; /* set up our mode so that you can read it anywhere */
-
- switch (mode[u]) { /* any un-handled modes return error from this module */
- case 2:
- msg();
- G->moduleresult=0;
- break;
- case 98:
- versionck(version); /* just return after this call, don't modify anything */
- break;
- case 0:
- strcpy (G->programmer,"W Gladnick"); /* show the programmer's name up to 20 chars*/
- G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
- break;
- default:
- G->moduleresult=1; /* return bad code */
- }
- HUnlock(temph); /* unlocks this module, do this ! */
- RestoreA4(); /* call this when you are all done */
- }
-
- msg(){
- char temp[256];
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
- loguser(G->modulename[u]); /* this tells where you are for remote sysop, or writes to log file */
-
- /* you print the following so that the sysop can monitor use on the mac screen */
-
- print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
-
- strcpy(temp,":Dis:");
- strcat(temp,G->modulename[u]);
- strcat(temp,".intro");
-
- sendtext(temp);
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
-
- loop:
- send("]] *** Discussions Section Menu *** (currently selected topic \"%s\")]]",G->modulename[u]);
- if (!(cmd1(">> Enter-msg, Read-all, New-msgs, Help, Quit :"))) goto byebye; /* timeout */
- send (G->CR[u]);
- switch (G->input[u]) {
- case 'E':
- msg_write();
- break;
- case 'R':
- last_read[u]=0;
- msg_read();
- break;
- case 'N':
- get_data();
- msg_read();
- put_data();
- break;
- case 'H':
- sendtext(":Dis:Discussions.help");
- break;
- case 'Q': /* Quit */
- return;
- break;
- }
- if (!G->online[u]) goto byebye; /* log out */
- goto loop;
- byebye:
- G->online[u]=FALSE; /* show we timed out */
- }
-
-
- msg_read(){
- unsigned char c;
- FILE *stream; /* my message file pointer */
- int counter,charcounter;
- int i,flag;
- char this_user[64],that_user[64],line[82],squiglyStr[5],last_read_str[8];
- char temp[256];
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
-
- counter=0;
- strcpy(squiglyStr,"~\n");
- strcpy(temp,":Dis:");
- strcat(temp,G->modulename[u]);
- strcat(temp,".text");
-
- if ((stream = fopen(temp,"r")) == NULL) return; /* open the message text file */
-
- if (last_read[u]==0) goto skip;
-
- while ( TRUE ){ /* read up to message last_read+1 */
- if( fgets(line,79,stream) == NULL ){
- send("]NO NEW MESSAGES]");
- fclose(stream);
- return;
- }
-
- if (strcmp(squiglyStr,line) == 0) ++counter; /* see if it's our end marker */
-
- if (counter == last_read[u]) break; /* stop if we found a new message */
-
- }/* end while*/
-
- skip:
-
- send (G->CR[u]);
- charcounter=0;
- flag=TRUE;
-
- while ((i = fgetc(stream)) != EOF) {
- if (flag) {
- send("____________________________________________________________________]");
- flag=FALSE;
- }
- ++charcounter;
- c = i & 0xFF;
- if (c == '~') {
- fgetc(stream); /* get the last character */
- charcounter=0;
- send("____________________________________________________________________]]");
- ++last_read[u];
- if (!(cmd1(">> Next (or press return), Quit :"))) {G->online[u]=FALSE; return;} /* timeout */
- if (G->input[u] == 'Q') { /* Quit */
- fclose(stream);
- return;
- }
- goto skip;
- }
- if (charcounter > 80) {
- send(G->CR[u]);
- charcounter=0;
- if ((c == 0x0A) || (c == 0x0D)) continue; /* don't send another CR! */
- }
- if ((c == 0x0A) || (c == 0x0D)) { send(G->CR[u]); charcounter=0;}
- else G->out(c);
- }
-
- send("]NO NEW MESSAGES]");
- fclose(stream);
-
- }/* close msg_read() */
-
-
- get_data()
- {
- /* When this routine is called, it tries to open the users data file */
- /* containing only the number of the last message he read(at this time)*/
- /* If the file isn't there, it creates the file and initializes it. */
-
- char data_str[256],user_last_read[128];
- FILE *stream;
-
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
-
- strcpy(data_str,":Dis:");
- strcat(data_str,G->username[u]);
- strcat(data_str,G->modulename[u]);
- strcat(data_str,".data");
-
- if ((stream=fopen(data_str,"r")) == NULL){ /* see if the file exists */
- stream=fopen(data_str,"w"); /* create a new file and make it show 0 */
- fputs("0\n",stream);
- last_read[u]=0;
- fclose(stream);
- }
- else{
- fgets(user_last_read,18,stream);
- sscanf(user_last_read,"%d",&last_read[u]);
- fclose(stream);
- }
- }
-
- put_data() /*This routine just updates the users data file*/
- {
- char data_str[79],user_last_read[20];
- FILE *stream;
-
- strcpy(data_str,":Dis:");
- strcat(data_str,G->username[u]);
- strcat(data_str,G->modulename[u]);
- strcat(data_str,".data");
- stream=fopen(data_str,"w");
- sprintf(user_last_read,"%d\n",last_read[u]);
- fputs(user_last_read,stream);
- fclose(stream);
- }
-
-
- msg_write()
- {
- char datetime[256],temp[256];
- int i;
- char fromstr[512];
- char timestr2[128];
- FILE *stream;
-
- struct EnterStruct S; /* make the struct right here (its now on the stack) */
-
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
-
- enteremail(&S);
-
- if (!G->online[u]) {G->online[u]=FALSE; return;} /* do this check so we can log out if hang up */
-
- if (S.result != 10) return; /* 10 means SAVE! */
-
- getmytime (datetime);
-
- strcpy(temp,":Dis:");
- strcat(temp,G->modulename[u]);
- strcat(temp,".text");
-
- if ((stream = fopen(temp,"a")) == NULL) return; /* if a file isn't there create one */
-
- strcpy(fromstr,"From : ");
- strcat(fromstr,G->username[u]);
- strcat(fromstr,"\nTo : All\nTime : ");
- strcat(fromstr,datetime);
- strcat(fromstr,"\n\n");
-
- fputs(fromstr,stream);
-
- i=0;
- while ( i <= S.numlines){
- fputs(S.emailtext[i],stream);
- fputs("\n",stream);
- i++;
- }
-
- fputs("~\n",stream);
- send("]Message saved]");
- fclose( stream );
- }
-
-
- enteremail(S) /* taken from "E-Mail" module source by Noam Freedman */
- struct EnterStruct *S;
- {
- char pad[100]; /* this is a fix for a problem */
- char ch;
- int a = 0, /* flag */
- i = 0, /* temp # holder */
- tf = FALSE, /* true/false flag */
- num; /* true/false flag when calling functions */
- S->numlines = 0; /* num lines */
-
- send("]]A line can contain 75 characters, max 50 lines.]");
- send("To end or edit, enter a carriage return on an empty line.]");
- send(" ---------1---------2---------3---------4---------5---------6---------7----!]");
-
- G->nocheck[u]=TRUE; /* no control checking on ouput ! */
- if( (S->numlines+1) < 9 )
- send(" %i: ",(S->numlines+1)); /* don't check for anything here */
- else
- send("%i: ",(S->numlines+1)); /* don't check for anything here */
- G->nocheck[u]=FALSE; /* turn it back on */
-
- while ( a == 0 )
- {
- if (!G->in()) {num = 2;goto byebye;} /* carrier detect or time out ? */
- ch = G->input[u];
- if ( ch == '~') continue; /* illegal char for DISCUSSIONS! */
- if ( ch == 13)
- {
- G->nocheck[u]=TRUE; /* no control checking on ouput ! */
- send(G->CR[u]); /* don't check for anything here */
- G->nocheck[u]=FALSE; /* turn it back on */
- if (S->numlines >= 49) i = 0;
- else S->numlines = S->numlines + 1;
-
- if (i == 0)
- {
- if(S->numlines <= 48) S->numlines = S->numlines - 2;
- num = askline(S);
- if (num != 0) goto byebye;
- }
- i = 0;
- S->emailtext[S->numlines][i]= '\0';
- G->nocheck[u]=TRUE; /* no control checking on ouput ! */
- if( (S->numlines+1) <= 9 )
- send(" %i: ",(S->numlines+1)); /* don't check for anything here */
- else
- send("%i: ",(S->numlines+1)); /* don't check for anything here */
- G->nocheck[u]=FALSE; /* turn it back on */
- }
- else
- if ( ch == 8 ) /* handle backspace */
- {
- if (i>0) {
- G->serout('\b');
- G->serout(' ');
- G->serout('\b');
- i--;
- S->emailtext[S->numlines][i] = '\0';
- }
- if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
- }
- else
- if ( i >= 74 )
- {
- G->serout(ch); /* doesn't check for "S" or "C" */
- if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
- if (S->numlines >= 49) continue;
- S->emailtext[S->numlines][i] = ch;
- S->emailtext[S->numlines][i+1] = '\0';
- S->numlines = S->numlines + 1;
- i = 0;
- G->nocheck[u]=TRUE; /* no control checking on ouput ! */
- send(G->CR[u]);
- if( (S->numlines+1) <= 9 )
- send(" %i: ",(S->numlines+1)); /* don't check for anything here */
- else
- send("%i: ",(S->numlines+1)); /* don't check for anything here */
- G->nocheck[u]=FALSE; /* turn it back on */
- }
- else
- {
- G->serout(ch); /* doesn't check for "S" or "C" */
- if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
- S->emailtext[S->numlines][i] = ch;
- S->emailtext[S->numlines][i+1] = '\0';
- i++;
- }
- }
- byebye:
- S->result = num;
- }
-
-
- askline(S)
- struct EnterStruct *S;
- {
- char tempstring[255], ch;
- int num = 0, /* flag */
- b = 0, /* flag */
- c = 0, /* temp variable */
- d = 0; /* temp variable */
-
- while ( b == 0 )
- {
- if (S->numlines == 0 && S->emailtext[0][0] == '\0') /* if no text at all */
- {
- send("]Message Cancelled.]");
- num = 1;
- b = 1;
- break;
- }
- if (!(cmd1("]]>> Continue, Delete line, Edit line, List, Save, Quit : ")))
- {
- G->online[u]=FALSE;
- b = 1;
- num = 2;
- }
- send(G->CR[u]);
- ch = G->input[u];
- switch (ch)
- {
- case 'C':
- if ( S->numlines <=48 )
- {
- S->numlines = S->numlines + 1;
- num = 0;
- b = 1;
- }
- else
- send("]Message is already 50 lines!]");
- break;
- case 'D':
- send("]Enter line number to delete, or RETURN to exit : ");
- portsin(tempstring,3);
- send(G->CR[u]);
- c = strtoint(tempstring);
- if (c <= 0) break;
- if (c > (S->numlines + 1)){
- send("]]There is no such line number.]]");
- break;
- }
- send("]Line #%d reads:]",c);
- send(S->emailtext[(c-1)]);
- cmd1("]]Are you sure you want to DELETE it (Y/N)? ");
- ch = G->input[u];
- send(G->CR[u]);
- if (ch=='Y'){
- for (d = (c-1); d <S->numlines; d++)
- strcpy(S->emailtext[d],S->emailtext[d+1]);
- S->numlines = S->numlines - 1;
- }
- else
- {
- send("]Line was not deleted.]");
- }
- break;
- case 'E':
- send("]]The edit-line option for the program has been unwritten as of yet.]");
- break;
- case 'S':
- if(S->numlines >49) S->numlines=49; /* just to make sure */
- num = 10;
- b = 1;
- break;
- case 'L':
- for (d = 0;d<=S->numlines && d<=49;d++)
- {
- if( (d+1) < 9 )
- send(" %i: %s]",(d+1),S->emailtext[d]);
- else
- send("%i: %s]",(d+1),S->emailtext[d]);
- if (G->cancel[u]) break; /* did they press cancel? */
- }
- send(G->CR[u]);
- break;
- case 'Q':
- cmd1("]Are you sure you want to quit (Y/N)? ");
- ch = G->input[u];
- send(G->CR[u]);
- if (ch=='Y')
- {
- send("]Message Cancelled.]");
- num = 1;
- b = 1;
- }
- break;
- }
-
- }
- return(num);
- }
-
- getmytime(datetime)
- char *datetime;
- {
- char temp[128];
- gettime("%I:%M:%S %p %A %B",temp); /* gets the date & time */
- strcpy(datetime,temp);
- gettime(" %d %Y (%m/%d/%y)",temp); /* gets the date & time */
- strcat(datetime,temp);
- }
-